|
|
|
|
|
|
|
Objects Talking to Each Other |
|
|
|
|
|
|
|
|
Humans talk to each other through interfaces (such as mouths for delivering a message and ears for receiving messages). The protocol for communicating is determined by the formal or informal grammatical rules of the language. Likewise, objects talk to each other via their interfaces and the protocols set forth by the designer for carrying out this communication. The public methods and properties of an object together compose the object's interface. This interface implements the protocol of the object. A protocol is the rule by which two objects communicate with each other to properly carry out some goal. One object's interface, then, dispatches a message to another object's interface. A message is a stimulus in the form of an event, value, an object, or a pointer to a method. Messages are the result of dynamic interaction between objects and actors at runtime. Again, the Sebring class will help you understand the interface. |
|
|
|
|
|
|
|
|
New Term: An interface describes the public methods and properties of an object. It is the facility by which clients communicate with the serving object. |
|
|
|
|
|
|
|
|
New Term: Protocol is the rule by which two objects communicate with each other to properly carry out some goal. |
|
|
|
|
|
|
|
|
New Term: A message is a stimulus in the form of an event, value, an object, or a pointer to a method. |
|
|
|
|
|
|
|
|
In your fuse box collection, you find that the fuses all interact with the same interface to relay electrical information to the engine (another object). In particular, the information flows to the engine's computer, which is another object, thereby making the engine an aggregate. The fuse box itself has an interface to each electrical component in the Sebring. The protocol is based on the fact that each component expects a particular voltage (message) of electricity through the fuse in order to shut itself down when a problem is encountered. (By problem, I mean the state of the car. The subsequent activities related to this state would be the scenario for defining how these objects interact.) If the voltage is the one the component expects for normal operations, the electrical message is ignored. |
|
|
|
|
|
|
|
|
Was that straightforward? In case it wasn't, let's look at another example: the automatic transmission as an object. The usual methods for an automatic transmission are park, drive on normal roads, drive on slight incline, drive on steep incline, drive in reverse, and free the transmission (neutral). Together, these selections (which would be modeled as methods in your models) represent the interface to the transmission. The protocol (gulp!) would involve the nasty details of the stick interaction with the gears, among others. |
|
|
|
|
|